package js;

import java.util.Scanner;

public class q门电路设计 {
    static int count = 0;

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int[][] op = new int[4][4];
        int[][] num = new int[5][5];
        num[0][0] = 1;
        num[0][1] = 0;
        num[0][2] = 1;
        num[0][3] = 0;
        num[0][4] = 1;

        dfs(0, 0, op, num);
        System.out.println(count);
        //在此输入您的代码...
        scan.close();
    }

    static void dfs(int row, int col, int[][] op, int[][] num) {
        if (row == 4) {
            int ans = cal(op, num);
            if (ans == 1) count++;
            return;
        }
        for (int i = 0; i < 3; i++) {
            // 三种门
            op[row][col] = i;
            if (col + 1 < 4 - row) {
                dfs(row, col + 1, op, num);
            } else {
                dfs(row + 1, 0, op, num);
            }
        }
    }

    static int cal(int[][] op, int[][] num) {
        for (int i = 0; i < 4; i++) {
            for (int  j = 0;  j < 4-i;  j++) {
                switch (op[i][j]){
                    case 0:
                        num[i+1][j] = num[i][j] ^ num[i][j + 1];
                        break;
                    case 1:
                        num[i+1][j] = num[i][j] & num[i][j + 1];
                        break;
                    case 2:
                        num[i+1][j] = num[i][j] | num[i][j + 1];
                        break;
                    default:
                        break;
                }

            }
        }
       
        return num[4][0];
    }
}
